package com.example.secondhandsysapi.Service;
import com.example.secondhandsysapi.Entity.GoodsInfo;
import com.example.secondhandsysapi.Mapper.GoodsInfoMapper;
import com.example.secondhandsysapi.Service.GoodsInfoService;
import com.example.secondhandsysapi.Vo.CategoryGoodsInfo;
import com.example.secondhandsysapi.Vo.GoodsPostInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

import static cn.hutool.core.date.DateUtil.formatDate;

@Service
public class GoodsInfoServiceImpl implements GoodsInfoService {
    @Autowired
    private GoodsInfoMapper goodsInfoMapper;
//前端商品搜索页面查询名称
    @Override
    public List<GoodsInfo> getAllGoodsInfo(String name) {
        return goodsInfoMapper.getAllGoodsInfo(name);
    }

    @Override
    public Integer deleteById(Integer goodsid) {
        Integer i =  goodsInfoMapper.deleteById(goodsid);
        return i;
    }

    @Override
    public List<GoodsInfo> getAllGoodsInfoByPrice(Integer price) {
        return goodsInfoMapper.getAllGoodsInfoByPrice(price);

    }

    @Override
    public List<GoodsInfo> getAllGoodsInfoByPriceAndName(String goodsName, Integer goodsPrice) {
        return goodsInfoMapper.getAllGoodsInfoByPriceAndName(goodsName, goodsPrice);
    }

    //后端商品管理，显示所有商品信息
    @Override
    public List<GoodsInfo> getAllBackendGoodsInfo() {
        return goodsInfoMapper.getAllBackendGoodsInfo();
    }

    //获取商品详情页的商品信息
    @Override
    public List<GoodsInfo> getAllGoodsDetailsInfoByGoodsId(Integer goods_id) {
        return goodsInfoMapper. getAllGoodsDetailsInfoByGoodsId(goods_id);
    }

    @Override
    public List<GoodsInfo> getAllGoodsInfoByCategoryId(Integer category_id) {
        return goodsInfoMapper.getAllGoodsInfoByCategoryId(category_id);
    }


    @Override
    public List<GoodsInfo> getAllGoodsInfoPostCategory(Date goods_post, Integer category_id) {
        return goodsInfoMapper.getAllGoodsInfoPostCategory(goods_post,category_id);
    }

    @Override
    public List<GoodsInfo> getAllUpdateGoodsInfo(Integer user_id, String goods_name) {
        return goodsInfoMapper.getAllUpdateGoodsInfo(user_id, goods_name);
    }

    @Override
    public List<GoodsInfo> getAllGoodsInfo1() {
        return goodsInfoMapper.getAllGoodsInfo1();
    }

    @Override
    public List<GoodsInfo> getAllGoodsInfoByName(String goods_name) {
        return goodsInfoMapper.getAllGoodsInfoByName( goods_name);
    }

    @Override
    public List<GoodsInfo> getAllGoodsInfoByID(Integer user_id) {
        return goodsInfoMapper.getAllGoodsInfoByID(user_id);
    }

    //获取分页信息
    @Override
    public PageInfo<GoodsInfo> getGoodsInfo(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<GoodsInfo> i= goodsInfoMapper.getAllUpdateGoodsInfo(null,"");
        PageInfo<GoodsInfo> pageInfo = new PageInfo<>(i);
        return pageInfo;
    }

    //通过时修改状态为1
    @Override
    public Integer updateStatus(Integer goods_id) {
        Integer i = goodsInfoMapper.updateStatus(goods_id);
        return 1;
    }

    //拒绝后按照goods_id找到商品，并修改备注
    @Override
    public Integer updateCheck_Info(String check_info, Integer goods_id) {
        Integer i=goodsInfoMapper.updateCheck_Info(check_info,goods_id);
        return i;
    }

    //插入商品发布信息
    @Override
    public Integer insertGoodsInfo(GoodsPostInfo goodsPostInfo) {
        Integer i = goodsInfoMapper.insertGoodsInfo(goodsPostInfo);
        return i;
    }

    //得到随机的几条商品信息
    @Override
    public List<GoodsInfo> getRandomGoodsInfo() {
        return goodsInfoMapper.getRandomGoodsInfo();
    }


    @Override
    public List<GoodsPostInfo> getPublicProduct(Integer user_id) {
        return goodsInfoMapper.getPublicProduct(user_id);
    }
    
    @Override
    public List<GoodsInfo> getAllGoodsInfoPost(Date goods_Post) {
      return goodsInfoMapper.getAllGoodsInfoPost(goods_Post);
    }

    //我发布的商品，点击修改回显商品信息
    @Override
    public List<GoodsInfo> getProductDetailById(Integer id) {
        return goodsInfoMapper.getProductDetailById(id);
    }
    
    @Override
    public List<GoodsInfo> getAllGoodsInfoCategory(Integer category_id) {
        return goodsInfoMapper.getAllGoodsInfoCategory(category_id);
    }

    @Override
    public Integer updateProductInfo(GoodsInfo goodsInfo) {
        return goodsInfoMapper.updateProductInfo(goodsInfo);
    }
    
    @Override
    public List<GoodsInfo> getAllGoodsInfo3() {
        return goodsInfoMapper.getAllGoodsInfo3();
    }

    @Override
    public List<CategoryGoodsInfo> getAllCategoryGoodsId(Integer category_id) {
        return goodsInfoMapper.getAllCategoryGoodsId(category_id);
    }

    @Override
    public List<GoodsInfo> getAllGoodsInfoName(String goods_name) {
        return goodsInfoMapper.getAllGoodsInfoName(goods_name);
    }

    @Override
    public List<GoodsInfo> getAllGoodsInfoByNa(String name) {
        return goodsInfoMapper.getAllGoodsInfoByNa(name);
    }


}
